package com.huluobo.a2208kotlindouyindemo.cart

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.CartBean
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2025/1/2.
 */
@HiltViewModel
class CartViewModel @Inject constructor(
    val apiService: ApiService
) : BaseViewModel() {
    val getCartSuccess by lazy { MutableLiveData<List<CartBean>>() }
    fun getCartList() {
        executeNetwork(
            { apiService.getCartList() },
            getCartSuccess::postValue
        )
    }

    val addCartSuccess by lazy { MutableLiveData<String>() }
    fun addToCart(body: RequestBody) {
        executeNetwork(
            { apiService.addToCart(body) },
            addCartSuccess::postValue
        )
    }

    val removeCartSuccess by lazy { MutableLiveData<String>() }
    fun removeCart(body: RequestBody) {
        executeNetwork(
            { apiService.addToCart(body) },
            removeCartSuccess::postValue
        )
    }

    val deleteCartSuccess by lazy { MutableLiveData<String>() }
    fun deleteCart(body: RequestBody) {
        executeNetwork(
            { apiService.deleteCart(body) },
            deleteCartSuccess::postValue
        )
    }

}